import {
  sampleSize, //获得随机数
  uniq, //去重
  take, //从0开始获得指定数组
  takeRight,
  slice//裁剪数组
} from "lodash"

// 示例方法，没有实际意义
export function trim(str: string) {
  return str.trim();
}

export function ArrayHas(Arr:string[], str:string[]|string){
  if(typeof str === 'string'){
    if(Arr.indexOf(str) > -1){
      return true;
    }
  }else{
    let allHas = true;
    str.forEach((item)=>{
      if(Arr.indexOf(item) < 0){//不包含就设置为false
        allHas = false;
      }
    })
    return allHas;
  }
  return false;
}

//获得偶数数量
export function getEvenCount(Arr:any[]){
  let evenCount = 0;
  Arr.forEach((item)=>{
    let initItem = parseInt(item);
    if(initItem % 2 == 0){
      evenCount++;
    }
  })
  return evenCount;
}

/**
 * 获取奇数偶数排列
 */
export function getOddAndEven(Arr:[]){
  let result:any = [];
  
  Arr.forEach((item)=>{
      let initItem = parseInt(item);
      if(initItem % 2 == 0){
          result.push(0);
      }else{
          result.push(1);
      }
  })

  return result.join("");
}

/**
 * 获取一组奇数偶数排列
 */
export function getOddAndEvenList(arr:[]){
  let result:any = [];
  arr.forEach((item) => {
      result.push(getOddAndEven(item));
  });
  return result;
}

//得到杀号数
export function getRemoveNumber(redBall:string[], shahaoRule:number[]){
  
  let number1 = parseInt(redBall[0]);
  let number2 = parseInt(redBall[1]);
  let number3 = parseInt(redBall[2]);
  let number4 = parseInt(redBall[3]);
  let number5 = parseInt(redBall[4]);
  let number6 = parseInt(redBall[5]);

  let removeNumberList:number[] = [];

  let rule1 = shahaoRule[0]
  if(rule1 > 0){
    let removeNum = removeNumber(number1 + rule1);
    removeNumberList.push(removeNum);//红1+3 等于下期要移除的号
  }

  let rule2 = shahaoRule[1]
  if(rule2 > 0){
    let removeNum = removeNumber(number2 + rule2);
    removeNumberList.push(removeNum);//红1+3 等于下期要移除的号
  }

  let rule3 = shahaoRule[2]
  if(rule3 > 0){
    let removeNum = removeNumber(number3 + rule3);
    removeNumberList.push(removeNum);//红1+3 等于下期要移除的号
  }

  let rule4 = shahaoRule[3]
  if(rule4 > 0){
    let removeNum = removeNumber(number4 + rule4);
    removeNumberList.push(removeNum);//红1+3 等于下期要移除的号
  }

  let rule5 = shahaoRule[4]
  if(rule5 > 0){
    let removeNum = removeNumber(number5 + rule5);
    removeNumberList.push(removeNum);//红1+3 等于下期要移除的号
  }

  let rule6 = shahaoRule[5]
  if(rule6 > 0){
    let removeNum = removeNumber(number6 + rule6);
    removeNumberList.push(removeNum);//红1+3 等于下期要移除的号
  }
  
  return removeNumberList;
}

function removeNumber(num:number):number{
  if(num >33){
    return num %33;
  }else{
    return num
  }
}

//把数字都转为2个数字的字符串
export function getNumberStr(arr:any[]):string[]{
  let returnArr:string[] = arr.map((item)=>{
    item = item+"";
    if(item.length == 1){
      item = "0" + item
    }
    return item;
  })
  return returnArr;
}

/**
 * 根据杀号数判断是否需要移除当前红球
*/
export function needRemove (redBall:[], removeNumber:[]){
  let maxLen = redBall.length + removeNumber.length;
  let redBall1 = getNumberStr(redBall);
  let removeNumber2 = getNumberStr(removeNumber);
  let totalBall = redBall1.concat(removeNumber2);//把需要比较的数和需要移除的数进行合并
  totalBall = uniq(totalBall);//然后进行去重
  if(totalBall.length == maxLen){
    //如果去重后数量=12，说明没有重复
    return false;
  }
  //否则说明有重复，返回true 需要移除
  return true;
}